package com.basic.modules.ykf.service.impl;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.basic.common.utils.PageUtils;
import com.basic.common.utils.ParamsModel;
import com.basic.common.utils.Query;
import com.basic.modules.sys.service.SysUserService;
import com.basic.modules.ykf.dao.YkfAccountInputRecordDao;
import com.basic.modules.ykf.entity.YkfAccountInputRecordEntity;
import com.basic.modules.ykf.model.YkfQualityTestingModel;
import com.basic.modules.ykf.service.YkfAccountInputRecordService;
import com.basic.modules.ykf.service.YkfQualityTestingService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;


@Service("ykfQualityTestingService")
public class YkfQualityTestingServiceImpl implements YkfQualityTestingService {


    @Autowired
    private YkfAccountInputRecordDao accountInputRecordDao;

    @Autowired
    private SysUserService sysUserService;

    @Override
    public PageUtils receptionPage(ParamsModel<YkfQualityTestingModel> params) {
        IPage<YkfAccountInputRecordEntity> page = new Query<YkfAccountInputRecordEntity>().getPage(BeanUtil.beanToMap(params.getPage()));
//        List<Long> powerUserIds = sysUserService.getPowerUserIds();
//        params.getCondition().setCreateUserIds(powerUserIds);
        List<Long> powerSubAccountIds = sysUserService.getPowerSubAccountIds();
        if (ObjectUtil.isEmpty(powerSubAccountIds)) {
            return new PageUtils();
        } else {
            if (!powerSubAccountIds.contains(0L)) {
                params.getCondition().setPowerSubAccountIds(powerSubAccountIds);
            }
        }
        IPage<YkfQualityTestingModel> iPage = accountInputRecordDao.receptionPage(page, params.getCondition());
        return new PageUtils(iPage);
    }
}
